﻿using System;
using Common.Tools;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestCommon.Tools
{
    [TestClass]
    public class TestRegexLib
    {
        #region 数值验证
        [TestMethod]
        public void IsValidDecimal()
        {
            bool bol = RegexLib.IsValidDecimal("1.2");
            Assert.IsTrue(bol, "1.2时应该为true");

            bol = RegexLib.IsValidDecimal("+1.2");
            Assert.IsTrue(bol, "+1.2时应该为true");

            bol = RegexLib.IsValidDecimal("-1.2");
            Assert.IsTrue(bol, "-1.2时应该为true");

            bol = RegexLib.IsValidDecimal("0.00000000000001");
            Assert.IsTrue(bol, "0.00000000000001时应该为true");

            bol = RegexLib.IsValidDecimal("0.00");
            Assert.IsTrue(bol, "0.00时应该为true");

            bol = RegexLib.IsValidDecimal("12345678901.1");
            Assert.IsTrue(bol, "小数12345678901.1时应该为true");

            bol = RegexLib.IsValidDecimal("12345678901");
            Assert.IsFalse(bol, "整数12345678901时应该为false");

            bol = RegexLib.IsValidDecimal("0.");
            Assert.IsFalse(bol, "0.时应该为false,格式错误");

            bol = RegexLib.IsValidDecimal("1");
            Assert.IsFalse(bol, "不可以为整数,1时应该为false");

            bol = RegexLib.IsValidDecimal("+1");
            Assert.IsFalse(bol, "不可以为正整数,+1时应该为false");

            bol = RegexLib.IsValidDecimal("-1");
            Assert.IsFalse(bol, "不可以为负整数,-1时应该为false");

            bol = RegexLib.IsValidDecimal("");
            Assert.IsFalse(bol, "空字符串时应该为false");

            bol = RegexLib.IsValidDecimal(null);
            Assert.IsFalse(bol, "null时应该为false");

            bol = RegexLib.IsValidDecimal("A");
            Assert.IsFalse(bol, "字母A时应该为false");

            bol = RegexLib.IsValidDecimal("我");
            Assert.IsFalse(bol, "中文我时应该为false");

            bol = RegexLib.IsValidDecimal(".");
            Assert.IsFalse(bol, "字符.时应该为false");

            bol = RegexLib.IsValidDecimal("+.");
            Assert.IsFalse(bol, "字符+.时应该为false");

            bol = RegexLib.IsValidDecimal("!@#$#$%");
            Assert.IsFalse(bol, "字符!@#$#$%时应该为false");
        }

        [TestMethod]
        public void IsValidDecimalOrNum()
        {
            bool bol = RegexLib.IsValidDecimalOrNum("1.2");
            Assert.IsTrue(bol, "1.2时应该为true");

            bol = RegexLib.IsValidDecimalOrNum("+1.2");
            Assert.IsTrue(bol, "+1.2时应该为true");

            bol = RegexLib.IsValidDecimalOrNum("-1.2");
            Assert.IsTrue(bol, "-1.2时应该为true");

            bol = RegexLib.IsValidDecimalOrNum("0.00000000000001");
            Assert.IsTrue(bol, "0.00000000000001时应该为true");

            bol = RegexLib.IsValidDecimalOrNum("0.00");
            Assert.IsTrue(bol, "0.00时应该为true");

            bol = RegexLib.IsValidDecimalOrNum("12345678901");
            Assert.IsTrue(bol, "整数12345678901时应该为true");

            bol = RegexLib.IsValidDecimalOrNum("0.");
            Assert.IsFalse(bol, "0.时应该为false,格式错误");

            bol = RegexLib.IsValidDecimalOrNum("1");
            Assert.IsTrue(bol, "可以为整数,1时应该为true");

            bol = RegexLib.IsValidDecimalOrNum("+1");
            Assert.IsTrue(bol, "可以为正整数,+1时应该为true");

            bol = RegexLib.IsValidDecimalOrNum("-1");
            Assert.IsTrue(bol, "可以为负整数,-1时应该为true");

            bol = RegexLib.IsValidDecimalOrNum("");
            Assert.IsFalse(bol, "空字符串时应该为false");

            bol = RegexLib.IsValidDecimalOrNum(null);
            Assert.IsFalse(bol, "null时应该为false");

            bol = RegexLib.IsValidDecimalOrNum("A");
            Assert.IsFalse(bol, "字母A时应该为false");

            bol = RegexLib.IsValidDecimalOrNum("我");
            Assert.IsFalse(bol, "中文我时应该为false");

            bol = RegexLib.IsValidDecimalOrNum(".");
            Assert.IsFalse(bol, "字符.时应该为false");

            bol = RegexLib.IsValidDecimalOrNum("+.");
            Assert.IsFalse(bol, "字符+.时应该为false");

            bol = RegexLib.IsValidDecimalOrNum("!@#$#$%");
            Assert.IsFalse(bol, "字符!@#$#$%时应该为false");
        }

        [TestMethod]
        public void IsNumber()
        {
            bool bol = RegexLib.IsNumber("1");
            Assert.IsTrue(bol, "可以为整数,1时应该为true");

            bol = RegexLib.IsNumber("+1");
            Assert.IsTrue(bol, "可以为正整数,+1时应该为true");

            bol = RegexLib.IsNumber("-1");
            Assert.IsTrue(bol, "可以为负整数,-1时应该为true");

            bol = RegexLib.IsNumber("0");
            Assert.IsTrue(bol, "可以为整数,0时应该为true");

            bol = RegexLib.IsNumber("12345678901");
            Assert.IsTrue(bol, "整数12345678901时应该为true");

            bol = RegexLib.IsNumber("1.2");
            Assert.IsFalse(bol, "1.2时应该为false");

            bol = RegexLib.IsNumber("+1.2");
            Assert.IsFalse(bol, "+1.2时应该为false");

            bol = RegexLib.IsNumber("-1.2");
            Assert.IsFalse(bol, "-1.2时应该为false");

            bol = RegexLib.IsNumber("0.00000000000001");
            Assert.IsFalse(bol, "0.00000000000001时应该为false");

            bol = RegexLib.IsNumber("0.00");
            Assert.IsFalse(bol, "0.00时应该为false");

            bol = RegexLib.IsNumber("0.");
            Assert.IsFalse(bol, "0.时应该为false,格式错误");

            bol = RegexLib.IsNumber("");
            Assert.IsFalse(bol, "空字符串时应该为false");

            bol = RegexLib.IsNumber(null);
            Assert.IsFalse(bol, "null时应该为false");

            bol = RegexLib.IsNumber("A");
            Assert.IsFalse(bol, "字母A时应该为false");

            bol = RegexLib.IsNumber("我");
            Assert.IsFalse(bol, "中文我时应该为false");

            bol = RegexLib.IsNumber(".");
            Assert.IsFalse(bol, "字符.时应该为false");

            bol = RegexLib.IsNumber("+.");
            Assert.IsFalse(bol, "字符+.时应该为false");

            bol = RegexLib.IsNumber("!@#$#$%");
            Assert.IsFalse(bol, "字符!@#$#$%时应该为false");
        }

        [TestMethod]
        public void IsInt()
        {
            bool bol = RegexLib.IsInt("1");
            Assert.IsTrue(bol, "整数1时应该为true");

            bol = RegexLib.IsInt("+1");
            Assert.IsTrue(bol, "整数+1时应该为true");

            bol = RegexLib.IsInt("-1");
            Assert.IsTrue(bol, "整数-1时应该为true");

            bol = RegexLib.IsInt("0");
            Assert.IsTrue(bol, "整数0时应该为true");

            bol = RegexLib.IsInt("0.01");
            Assert.IsFalse(bol, "小数0.01时应该为false");

            bol = RegexLib.IsInt("12345678901");
            Assert.IsFalse(bol, "整数12345678901时应该为false,int最大值为" + int.MaxValue);

            bol = RegexLib.IsInt("+");
            Assert.IsFalse(bol, "字符+时应该为false");

            bol = RegexLib.IsInt("A");
            Assert.IsFalse(bol, "字母A时应该为false");

            bol = RegexLib.IsInt("乌尔禾");
            Assert.IsFalse(bol, "中文时应该为false");

            bol = RegexLib.IsInt("!@#.$%^");
            Assert.IsFalse(bol, "特殊字符时应该为false");

            bol = RegexLib.IsInt("");
            Assert.IsFalse(bol, "空字符串时应该为false");

            bol = RegexLib.IsInt(null);
            Assert.IsFalse(bol, "null时应该为false");
        }

        [TestMethod]
        public void IsPositive()
        {
            bool bol = RegexLib.IsPositive("1");
            Assert.IsTrue(bol, "整数1时应该为true");

            bol = RegexLib.IsPositive("+1");
            Assert.IsTrue(bol, "整数+1时应该为true");

            bol = RegexLib.IsPositive("0");
            Assert.IsTrue(bol, "整数0时应该为true");

            bol = RegexLib.IsPositive("12345678901");
            Assert.IsTrue(bol, "整数12345678901时应该为true");

            bol = RegexLib.IsPositive("-1");
            Assert.IsFalse(bol, "整数-1时应该为false");

            bol = RegexLib.IsPositive("0.01");
            Assert.IsFalse(bol, "小数0.01时应该为false");

            bol = RegexLib.IsPositive("+");
            Assert.IsFalse(bol, "字符+时应该为false");

            bol = RegexLib.IsPositive("A");
            Assert.IsFalse(bol, "字母A时应该为false");

            bol = RegexLib.IsPositive("乌尔禾");
            Assert.IsFalse(bol, "中文时应该为false");

            bol = RegexLib.IsPositive("!@#.$%^");
            Assert.IsFalse(bol, "特殊字符时应该为false");

            bol = RegexLib.IsPositive("");
            Assert.IsFalse(bol, "空字符串时应该为false");

            bol = RegexLib.IsPositive(null);
            Assert.IsFalse(bol, "null时应该为false");
        }

        [TestMethod]
        public void IsBarringZeroPositive()
        {
            bool bol = RegexLib.IsBarringZeroPositive("1");
            Assert.IsTrue(bol, "整数1时应该为true");

            bol = RegexLib.IsBarringZeroPositive("+1");
            Assert.IsTrue(bol, "整数+1时应该为true");

            bol = RegexLib.IsBarringZeroPositive("12345678901");
            Assert.IsTrue(bol, "整数12345678901时应该为true");

            bol = RegexLib.IsBarringZeroPositive("0");
            Assert.IsFalse(bol, "整数0时应该为false");

            bol = RegexLib.IsBarringZeroPositive("-1");
            Assert.IsFalse(bol, "整数-1时应该为false");

            bol = RegexLib.IsBarringZeroPositive("0.01");
            Assert.IsFalse(bol, "小数0.01时应该为false");

            bol = RegexLib.IsBarringZeroPositive("+");
            Assert.IsFalse(bol, "字符+时应该为false");

            bol = RegexLib.IsBarringZeroPositive("A");
            Assert.IsFalse(bol, "字母A时应该为false");

            bol = RegexLib.IsBarringZeroPositive("乌尔禾");
            Assert.IsFalse(bol, "中文时应该为false");

            bol = RegexLib.IsBarringZeroPositive("!@#.$%^");
            Assert.IsFalse(bol, "特殊字符时应该为false");

            bol = RegexLib.IsBarringZeroPositive("");
            Assert.IsFalse(bol, "空字符串时应该为false");

            bol = RegexLib.IsBarringZeroPositive(null);
            Assert.IsFalse(bol, "null时应该为false");
        }
        #endregion

        #region 格式验证
        [TestMethod]
        public void IsChinese()
        {
            bool bol = RegexLib.IsChinese("我");
            Assert.IsTrue(bol, "我时应该为false");

            bol = RegexLib.IsChinese("卍");
            Assert.IsTrue(bol, "卍时应该为true");

            bol = RegexLib.IsChinese("氵");
            Assert.IsTrue(bol, "氵时应该为true");

            bol = RegexLib.IsChinese("，");
            Assert.IsFalse(bol, "，时应该为false");

            bol = RegexLib.IsChinese(",");
            Assert.IsFalse(bol, ",时应该为false");

            bol = RegexLib.IsChinese("*");
            Assert.IsFalse(bol, "*时应该为false");

            bol = RegexLib.IsChinese("ABC");
            Assert.IsFalse(bol, "ABC时应该为false");

            bol = RegexLib.IsChinese("1.2");
            Assert.IsFalse(bol, "1.2时应该为false");

            bol = RegexLib.IsChinese(" ");
            Assert.IsFalse(bol, " 时应该为false");

            bol = RegexLib.IsChinese("");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("ㅏ");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("Л");
            Assert.IsFalse(bol, "Л时应该为false");

            bol = RegexLib.IsChinese("┌");
            Assert.IsFalse(bol, "┌时应该为false");

            bol = RegexLib.IsChinese("あ");
            Assert.IsFalse(bol, "あ时应该为false");

            bol = RegexLib.IsChinese("ā");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("α");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("Ω");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("≌");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("±");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("m³");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("①");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("⑴");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("⒈");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("Ⅰ");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("㈠");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("《");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("※");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("©");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("®");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("☯");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsChinese("☁");
            Assert.IsFalse(bol, "时应该为false");
        }

        [TestMethod]
        public void IsDoubleByte()
        {
            bool bol = RegexLib.IsDoubleByte(",");
            Assert.IsFalse(bol, ",时应该为false");

            bol = RegexLib.IsDoubleByte("*");
            Assert.IsFalse(bol, "*时应该为false");

            bol = RegexLib.IsDoubleByte("ABC");
            Assert.IsFalse(bol, "ABC时应该为false");

            bol = RegexLib.IsDoubleByte("1.2");
            Assert.IsFalse(bol, "1.2时应该为false");

            bol = RegexLib.IsDoubleByte(" ");
            Assert.IsFalse(bol, " 时应该为false");

            bol = RegexLib.IsDoubleByte("");
            Assert.IsFalse(bol, "时应该为false");

            bol = RegexLib.IsDoubleByte("±");
            Assert.IsFalse(bol, "±时应该为false");

            bol = RegexLib.IsDoubleByte("³");
            Assert.IsFalse(bol, "³时应该为false");

            bol = RegexLib.IsDoubleByte("©");
            Assert.IsFalse(bol, "©时应该为false");

            bol = RegexLib.IsDoubleByte("®");
            Assert.IsFalse(bol, "®时应该为false");

            bol = RegexLib.IsDoubleByte("我");
            Assert.IsTrue(bol, "我时应该为false");

            bol = RegexLib.IsDoubleByte("卍");
            Assert.IsTrue(bol, "卍时应该为true");

            bol = RegexLib.IsDoubleByte("氵");
            Assert.IsTrue(bol, "氵时应该为true");

            bol = RegexLib.IsDoubleByte("，");
            Assert.IsTrue(bol, "，时应该为true");

            bol = RegexLib.IsDoubleByte("ㅏ");
            Assert.IsTrue(bol, "ㅏ时应该为true");

            bol = RegexLib.IsDoubleByte("Л");
            Assert.IsTrue(bol, "Л时应该为true");

            bol = RegexLib.IsDoubleByte("┌");
            Assert.IsTrue(bol, "┌时应该为true");

            bol = RegexLib.IsDoubleByte("あ");
            Assert.IsTrue(bol, "あ时应该为true");

            bol = RegexLib.IsDoubleByte("ā");
            Assert.IsTrue(bol, "ā时应该为true");

            bol = RegexLib.IsDoubleByte("α");
            Assert.IsTrue(bol, "α时应该为true");

            bol = RegexLib.IsDoubleByte("Ω");
            Assert.IsTrue(bol, "Ω时应该为true");

            bol = RegexLib.IsDoubleByte("≌");
            Assert.IsTrue(bol, "≌时应该为true");

            bol = RegexLib.IsDoubleByte("①");
            Assert.IsTrue(bol, "①时应该为true");

            bol = RegexLib.IsDoubleByte("⑴");
            Assert.IsTrue(bol, "⑴时应该为true");

            bol = RegexLib.IsDoubleByte("⒈");
            Assert.IsTrue(bol, "⒈时应该为true");

            bol = RegexLib.IsDoubleByte("Ⅰ");
            Assert.IsTrue(bol, "Ⅰ时应该为true");

            bol = RegexLib.IsDoubleByte("㈠");
            Assert.IsTrue(bol, "㈠时应该为true");

            bol = RegexLib.IsDoubleByte("《");
            Assert.IsTrue(bol, "《时应该为true");

            bol = RegexLib.IsDoubleByte("※");
            Assert.IsTrue(bol, "※时应该为true");

            bol = RegexLib.IsDoubleByte("☯");
            Assert.IsTrue(bol, "☯时应该为true");

            bol = RegexLib.IsDoubleByte("☁");
            Assert.IsTrue(bol, "☁时应该为true");
        }
        #endregion
    }
}
